package jheej5024_01;

import java.util.Scanner;

public class SungJukSVC  implements ISungJukSVC {

	SungJukVO sv =null;
	Scanner sc = null;
	SungJukDAO sjdao = null;
	
	public SungJukSVC() {
		sv=new SungJukVO();
		sc=new Scanner(System.in);
		sjdao = new SungJukDAO();
	}
	
	@Override
	public void createSungJuk() {
		System.out.println("성적등록");
		System.out.println("이름입력"); sv.setName(sc.next());
		System.out.println("국어점수 입력"); sv.setKor(sc.nextInt());
		System.out.println("영어점수 입력"); sv.setEng(sc.nextInt());
		System.out.println("수학점수 입력"); sv.setMat(sc.nextInt());
		sv.setTot( sum(sv.getKor(), sv.getEng(),sv.getMat()));
		sv.setAvg(avg(sv.getTot()));
		sv.setGrd(grade(sv.getAvg()));
		if(sjdao.insertSungJuk(sv))
			System.out.println("등록되었습니다");
		else
			System.out.println("등록실패");
		
		
	}

	@Override
	public void readSungJuk() {
		
	}

	@Override
	public void updateSungJuk() {
		
	}

	@Override
	public void deleteSungJuk() {
		
	}
	
	int sum(int kor, int eng, int mat){
		return kor+eng+mat;
	}
	float avg(int sum) {
		return sum/3;
	}
	String grade(float avg) {
		
		String grade = "";
		switch((int)avg/10){
		case 10: case 9: grade="A";break;
		case 8: grade="B"; break;
		case 7: grade="C"; break;
		case 6: grade="D"; break;
		default:grade="F";
		}
		return grade;
		
	}

}
